package com.example.datamaskingdemo.formatter;

import com.example.datamaskingdemo.enumType.SensitiveTypeEnum;
import com.example.datamaskingdemo.utils.DesensitizedUtils;
import org.springframework.format.Formatter;
import org.springframework.util.StringUtils;

import java.text.ParseException;
import java.util.Locale;

public class DesensitizedFormatter implements Formatter<String> {
    private SensitiveTypeEnum typeEnum;

    public SensitiveTypeEnum getTypeEnum() {
        return typeEnum;
    }

    public void setTypeEnum(SensitiveTypeEnum typeEnum) {
        this.typeEnum = typeEnum;
    }

    @Override
    public String parse(String s, Locale locale) throws ParseException {
        if (!StringUtils.isEmpty(s)){
            switch (typeEnum){
                case TELEPHONE:
                    s = DesensitizedUtils.telephone(s);
                    break;
            }
        }
        return s;
    }

    @Override
    public String print(String s, Locale locale) {
        return s;
    }
}